import 'package:flutter/cupertino.dart';
import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';

import '../ui/select_room_page.dart';

class BottomInputRoomWidget extends StatefulWidget {
  final String title;
  final String hint;
  final String btnText;
  final Function(String str)? onSubmit;
  final CommonInputType keyboard;

  String content = "";

  BottomInputRoomWidget(
      {this.title = "请输入",
      this.hint = "请输入",
      this.btnText = "确定",
      this.onSubmit,
      this.content = "",
      this.keyboard = CommonInputType.multiline}) ;

  @override
  State<StatefulWidget> createState() => _BottomInputRoomState();




}

class _BottomInputRoomState extends State<BottomInputRoomWidget>{

  TextEditingController? controller;
  @override
  void initState() {
    controller = TextEditingController.fromValue(TextEditingValue(text: widget.content));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            CommonText(widget.title, fontWeight: FontWeight.w600, textSize: 20),
            // TextButton(
            //     onPressed: () async {
            //       var address = await Go().push(SelectRoomPage());
            //       setState(() {
            //         controller?.text = address;
            //       });
            //
            //     },
            //     child: Text('选择房间'))
          ],
        ),
        Container(
          height: 10,
        ),
        TextField(
          controller: controller,
          decoration: InputDecoration.collapsed(
            hintText: widget.hint,
            border: InputBorder.none,
          ),
          onChanged: (str) {
            // setState((){
            //   controller.text = str;
            // });
          },
          // padding: EdgeInsets.zero,
          maxLines: 5,
        ).addToContainer(
            decoration: BoxDecoration(
                color: Colors.grey[200], borderRadius: 6.borderRadius),
            padding: EdgeInsets.all(8)),
        Container(
          height: 16,
        ),
        ElevatedButton(
          onPressed: () {
            if (widget.onSubmit != null) {
              Navigator.pop(context);
              if(widget.onSubmit!=null){
                widget.onSubmit!(controller?.value.text??"");
              }

            }
          },
          child: CommonText(widget.btnText, textColor: Colors.white),
          style: ButtonStyle(
              elevation: WidgetStateProperty.all(0),
              shape: WidgetStateProperty.all(StadiumBorder()),
              minimumSize:
              WidgetStateProperty.all(Size(double.infinity, 45))),
        )
      ],
    ).addToContainer(
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius:
            BorderRadius.only(topRight: 10.radius, topLeft: 10.radius)),
        padding: EdgeInsets.all(16));
  }

}

void showBottomInputRoomAddress(BuildContext context,
    {String title = "请输入",
    String hint = "请输入",
    String btnText = "确定",
    String content = "",
    CommonInputType keyboard = CommonInputType.multiline,
    Function(String str)? onSubmit}) {
  showModalBottomSheet(
      context: context,
      builder: (context) {
        return SingleChildScrollView(
          child: BottomInputRoomWidget(
            title: title,
            hint: hint,
            btnText: btnText,
            onSubmit: onSubmit,
            content: content,
            keyboard: keyboard,
          ),
          padding:
              EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
        );
      },
      backgroundColor: Colors.transparent,
      isScrollControlled: true);
}
